<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>采购订单查询</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, rgba(75, 175, 255, 0.8), rgba(255, 125, 120, 0.8)), url('background.jpg') no-repeat center center/cover;
            backdrop-filter: blur(10px);
            background-attachment: fixed;
        }
        .container {
            width: 90%;
            max-width: 800px;
            background-color: rgba(255, 255, 255, 0.9);
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
            margin-top: 50px;
        }
        .container h2 {
            text-align: center;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
        }
        .form-group input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .form-group button {
            width: 100%;
            padding: 10px;
            background-color: #4caf50;
            border: none;
            border-radius: 5px;
            color: white;
            font-size: 16px;
            cursor: pointer;
        }
        .form-group button:hover {
            background-color: #45a049;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 10px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>

<div class="container">
    <h2>查询采购订单</h2>
    <div class="form-group">
        <label for="startDate">开始日期:</label>
        <input type="datetime-local" id="startDate" name="startDate">
    </div>
    <div class="form-group">
        <label for="endDate">结束日期:</label>
        <input type="datetime-local" id="endDate" name="endDate">
    </div>
    <div class="form-group">
        <button onclick="fetchOrders()">查询</button>
    </div>
    <table id="ordersTable">
        <thead>
        <tr>
            <th>采购清单号</th>
            <th>员工编号</th>
            <th>采购数量</th>
            <th>采购总价</th>
            <th>采购时间</th>
            <th>备注</th>
        </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>

<script>
    function fetchOrders() {
        const startDate = document.getElementById('startDate').value;
        const endDate = document.getElementById('endDate').value;

        fetch(`http://localhost:8089/purchaseorder/purchaseorders?startDate=${startDate}&endDate=${endDate}`)
            .then(response => response.json())
            .then(data => {
                const tableBody = document.getElementById('ordersTable').getElementsByTagName('tbody')[0];
                tableBody.innerHTML = ''; // Clear existing table rows

                if (data.code === 1) {
                    data.data.forEach(order => {
                        const row = tableBody.insertRow();
                        row.insertCell(0).innerText = order.orderID;
                        row.insertCell(1).innerText = order.employeeID;
                        row.insertCell(2).innerText = order.quantity;
                        row.insertCell(3).innerText = order.totalPrice;
                        // Format orderDate to remove 'T' character
                        row.insertCell(4).innerText = order.orderDate.replace('T', ' ');
                        row.insertCell(5).innerText = order.notes;
                    });
                } else {
                    alert('查询失败: ' + data.msg);
                }
            })
            .catch(error => {
                console.error('Error fetching orders:', error);
                alert('查询失败，请稍后再试。');
            });
    }
</script>

</body>
</html>
